<template>
  <div>
    <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
      <div class="widget am-cf">
        <div class="widget-head am-cf">
          <div class="widget-title am-fl">超时资源</div>
        </div>
        <div class="widget-body  am-fr">
          <customer-toolbar ref="toolbar"  class="toolbar" @search="handleFind"
            areaTeam campusTeam  priority  followStatus visitStatus alloCreateTime
          ></customer-toolbar>
          <!-- <div class="am-u-sm-12 am-u-md-12 am-form-group am-fl">
            <button @click="handleAllo('campus')" type="button" class="btn-search am-btn am-btn-default am-btn-success">
              分配到校区
            </button> -->
            <!--<button @click="handleAllo('operator')" type="button" class="btn-search am-btn am-btn-default am-btn-success">-->
              <!--分配跟进人-->
            <!--</button>-->
          <!-- </div> -->
          <div class="am-u-sm-12">
            <el-table
              :data="tableData"
              border
              maxHeight="600"
              empty-text="暂无数据"
              stripe
              @selection-change="handleSelectionChange"
              style="min-width: 100%">
              <el-table-column
                type="selection"
                width="55">
              </el-table-column>
              <el-table-column
                min-width="100"
                prop="studentName"
                label="学生姓名">

              </el-table-column>
              <el-table-column
                min-width="130"
                prop="phoneNo"
                label="学生电话">
              </el-table-column>
              <el-table-column
                min-width="150"
                prop="campusName"
                label="分配校区">
              </el-table-column>
              <el-table-column
                min-width="100"
                label="紧急程度">
                <template scope="scope">
                  <div>{{{'0' : '低' ,'1': '中', '2': '高'}[scope.row.priority]}}</div>
                </template>
              </el-table-column>
              <el-table-column
                min-width="100"
                prop="followOperatorName"
                label="抢占人">
              </el-table-column>
              <el-table-column
                min-width="165"
                label="分配时间">
                <template scope="scope">
                  <div>{{scope.row.alloCreateTime | formatTime}}</div>
                </template>
              </el-table-column>
              <el-table-column
                min-width="100"
                prop="areaTeamName"
                label="跟进状态">
                <template scope="scope">
                  <div>{{scope.row.visitStatus === '0' ? '未跟进' : '已跟进'}}</div>
                </template>
              </el-table-column>
            </el-table>
          </div>
        </div>
        <div class="am-u-lg-12 am-cf">
          <div class="am-fr">
            <pagination v-bind:total="total" v-bind:pageNo="pageNo" v-bind:pageSize="pageSize"
                        @paging="loadTableData"/>
          </div>
        </div>
        <dispatch-detail @completed="loadTableData" ref="dispatchDetail"></dispatch-detail>
      </div>
    </div>
  </div>
</template>
<script>
  import io from '../../lib/io'
  import CustomerToolbar from './CustomerToolbar.vue'
  import Pagination from '../base/Pagination.vue'
  import moment from 'moment'
  import DispatchDetail from './DispatchDetail.vue'

  export default{
    data:function(){
      return {
        total: 0,
        pageSize: 10,
        pageNo: 1,
        tableData: [],
        checkList: [],
      }
    },
    components: {
      CustomerToolbar, Pagination, DispatchDetail
    },
    mounted :function(){
      $(window).smoothScroll()
    },
    methods:{
      handleSelectionChange (val) {
        this.checkList = val
      },
      handleAllo (type) {
        let customerResourceIds = []
        if (this.checkList.length === 0) {
          this.$alert('请至少选择一条记录！')
          return
        }
        this.checkList.map (val => {
          if (val.alloStatus === '0') {
            customerResourceIds.push(val.customerResourceId)
          }
        })
        if (customerResourceIds.length === 0) {
          this.$alert('您选择的记录都已经分配校区，请重新选择！')
        } else {
          this.$refs.dispatchDetail.type = type
          this.$refs.dispatchDetail.show()
          this.$refs.dispatchDetail.customerResourceId = customerResourceIds
          this.$refs.dispatchDetail.checkLength = this.checkList.length
        }
      },
      handleFind(formData) {
        this.formData = this.formatData(formData)
        this.loadTableData(1)
      },
      loadTableData: function (pageNo) {
        this.pageNo = pageNo || this.pageNo || 1
        this.$showLoading()
        io.post(io.customerResource, Object.assign({}, this.formData, {
          pageNo: this.pageNo,
          pageSize: this.pageSize,
        }), (ret) => {
          this.$hiddenLoading()
          if (ret.success) {
            this.tableData = ret.data.list
            this.total = ret.data.total
          } else {
            this.$alert(ret.desc)
          }
        })
      },
      formatData(data) {
        return {
            areaTeamId: data.areaTeamId,
            campusId: data.campusId,
            priority: data.priority,
            visitStatus: data.visitStatus,
            alloStatus: data.alloStatus,
            studentName: data.studentName,
            timeoutStatus:1,
            phoneNo: data.phoneNo,
            followStatus: data.followStatus,
            importOperatorName: data.importOperatorName,
            followOperatorName: data.followOperatorName,
            createTimeOfStart: data.createTime[0] ? moment(data.createTime[0]).format('YYYY-MM-DD') : '',
            createTimeOfEnd: data.createTime[1] ? moment(data.createTime[1]).format('YYYY-MM-DD') : '',
            alloCreateTimeOfStart:data.alloCreateTime[0] ? moment(data.alloCreateTime[0]).format('YYYY-MM-DD'):'',
            alloCreateTimeOfEnd:data.alloCreateTime[1] ? moment(data.alloCreateTime[1]).format('YYYY-MM-DD'):'',
        }
      }
    }
  }
</script>
<style lang="less" scoped>
</style>
